//author: dschuetz


package com.me.mygdxgame.Components;



import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;

import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.me.mygdxgame.Component;
import com.me.mygdxgame.TabletWars;


public class Render extends Component
{
	
	public Render(Texture texture)
	{
		this.texture = texture;
		
	}
	
	
	public Render()
	{}
	

	private Texture texture;
	private Sprite sprite;
	public int width;
	public int height;
	public boolean active = true;
	
	public static final int FRAME_COLS = 6;
	public static final int FRAME_ROWS = 5;
	
	public Animation walkAnimation;
	public Texture walkSheet;
	public TextureRegion[] walkFrames;
	public SpriteBatch spriteBatch;
	public TextureRegion currentFrame;
	
	public float stateTime;
	
	
	
	
	public void animation()
	{
		
		walkSheet = new Texture(Gdx.files.internal("data/animation_sheet.png"));
		TextureRegion[][] tmp = TextureRegion.split(walkSheet, walkSheet.getWidth()/ FRAME_COLS, walkSheet.getHeight()/ FRAME_ROWS);
		walkFrames = new TextureRegion[FRAME_COLS * FRAME_ROWS];
		int index = 0;
		for (int i = 0; i < FRAME_ROWS; i++) {
			for (int j = 0; j < FRAME_COLS; j++) {
				walkFrames[index++] = tmp[i][j];
			}
		}
		walkAnimation = new Animation(0.025f, walkFrames);
		spriteBatch = new SpriteBatch();
		stateTime = 0f;
		
	}
	
	
	public void  setAnimation()
	{} //add Textures for Animation
	
	public void render(SpriteBatch batch)
	{
		Transform transform = (Transform) this.parentObject.getComponent("Transform");
		if(active)
		{
		batch.draw(texture, transform.getPosition().x,reverseYAxis(transform.getPosition().y)-transform.getSize().y, transform.getSize().x, transform.getSize().y);
		}
		
		
		
				
		
	}
	
	float reverseYAxis(float value){
		int reverse = -1;
		return  value * reverse + TabletWars.h;
	}
	

	
	
	
	

public void setTexture(Texture texture)
{
	
	this.texture = texture;
}


	
	}

